/**
  CNOK project, Anyang Normal University, IMP-CAS
  \brief Just for debugging of the primary project.
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2022/06/20
  \date Last modified: 2020/06/20 by SUN Yazhou
  \copyright 2020-2023 SUN Yazhou
  \copyright CNOK project, Anyang Normal University, IMP-CAS
*/

#include <iostream>
#include <ctime>

#include "TH1F.h"
// #include "TGraph.h"
#include "TCanvas.h"
#include "TAConvolve.h"

using std::cout;
using std::endl;

int main(){
  clock_t start = clock();
  const int n = 500;
  TH1F *h0 = new TH1F("h0", "h0", n, -5., 5.);
  h0->FillRandom("gaus",50000);
  // TGraph *g0 = new TGraph(n);

  double x[n], f[n]; // ,ff[n]. f: original; ff: smeared
  for(int i = 0; i < n; i++){
    x[i] = h0->GetBinCenter(i);
    f[i] = h0->GetBinContent(i);
    // g0->SetPoint(i, x[i], f[i]);
  } // end for over i

  TH1F *h1 = new TH1F("h1", "h1", n, -5., 5.);
  // TGraph *g1 = new TGraph(n);
  for(int i = 0; i < 50000; i++) h1->Fill(TAConvolve::HitOrMiss(n, x, f));
  // h1->Scale(0.1);
  cout << h1->GetRMS() << endl;

  TCanvas *c = new TCanvas("c", "c", 1200, 600);
  c->Divide(2);
  c->cd(1); h0->Draw("e");
  c->cd(2); h1->Draw();
  c->Print("c.pdf");

  clock_t finish = clock();
  cout << finish << " " << start << " " << finish - start << endl;
  const double tt = double(finish - start) / CLOCKS_PER_SEC;
  cout << "The program takes " << tt << " seconds to finish." << endl;

  return 0;
} // end main function
